﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SuuntoWebsite.Events._201205
{
    public partial class Waitting : System.Web.UI.Page
    {
        protected string rewrite = System.Configuration.ConfigurationManager.AppSettings["rewriteType"];
        protected static string sqlCon = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString_Event"].ConnectionString;
        protected string userId = Public.Cookie.UserId;
        protected string productId = string.Empty;
        protected string userName = Public.Cookie.UserName;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Public.Cookie.UserId.Equals("0"))
                Response.Redirect("./registration" + rewrite);
            else
            {
                productId = Request["pd"];
                Public.Cookie.ProductId = productId;
                OrderCreate();
            }
            
        }
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        protected void OrderCreate()
        {
            //订单实体
            Model.ModelEvent.ModelSuunto_Order model = new Model.ModelEvent.ModelSuunto_Order();
            model.PKID = new Bll.EventForSuunto.BLLSuunto_Order().GetOrderID(sqlCon);
            model.UID = Public.Cookie.UserId;
            model.PID = Convert.ToInt32(Public.Cookie.ProductId);
            model.Money = 0.00;
            model.TakeAddress = 0;
            model.Count = 1;
            model.KeyCode = DateTime.Now.ToString("yyyyMMdd") + model.PKID.Substring(17, 3);
            model.State = "缺货预约";
            //保存订单
            bool flag = new Bll.EventForSuunto.BLLSuunto_Order().SuuntoOrderInsert(sqlCon, model);
            //保存成功调取支付宝方法
            if (flag) BindData(model.PKID);
        }
        private void BindData(string order_no)
        {
            DataTable dt = new Bll.EventForSuunto.BLLSuunto_Order().SuuntoOrderByPKID(sqlCon, order_no);
            if (dt.Rows.Count > 0)
            {
                OrderInfo.DataSource = dt;
                OrderInfo.DataBind();
                DataTable emailDt = new Bll.EventForSuunto.DALSuunto_Email().GetEmailConfig(sqlCon);
                Public.SendEmail.Sendmail(emailDt, dt.Rows[0]["S_Email"].ToString(), "验证码",
                                          dt.Rows[0]["O_Code"].ToString());
                dt.Dispose();
                Public.Cookie.UserId = "0";
                Public.Cookie.UserName = "0";
                Public.Cookie.StoreId = "0";
                Public.Cookie.ProductId = "0";
            }
        }
        public string GetGender(object obj)
        {
            if (obj.ToString() == "男")
                return "先生";
            else
                return "女士";

        }
    }
}
